From: Keir Fraser Date: Mon, 20 Oct 2008 16:16:45 +0000 (+0100) Subject: spinlock: Modify recursive spinlock definitions to support up to 4095 CPUs. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~14066^2~16 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=fe5e1a6aad56ca585e092eeb965f58b1e09c2c4f;p=xen.git spinlock: Modify recursive spinlock definitions to support up to 4095 CPUs. Signed-off-by: Keir Fraser --- diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 9e9369a432..15420ebfe7 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -57,11 +57,18 @@ void _spin_barrier(spinlock_t *lock) void _spin_lock_recursive(spinlock_t *lock) { int cpu = smp_processor_id(); + + /* Don't allow overflow of recurse_cpu field. */ + BUILD_BUG_ON(NR_CPUS > 0xfffu); + if ( likely(lock->recurse_cpu != cpu) ) { spin_lock(lock); lock->recurse_cpu = cpu; } + + /* We support only fairly shallow recursion, else the counter overflows. */ + ASSERT(lock->recurse_cnt < 0xfu); lock->recurse_cnt++; } @@ -69,7 +76,7 @@ void _spin_unlock_recursive(spinlock_t *lock) { if ( likely(--lock->recurse_cnt == 0) ) { - lock->recurse_cpu = -1; + lock->recurse_cpu = 0xfffu; spin_unlock(lock); } } diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index 30ce057667..289018fea0 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -7,11 +7,11 @@ typedef struct { raw_spinlock_t raw; - s8 recurse_cpu; - u8 recurse_cnt; + u16 recurse_cpu:12; + u16 recurse_cnt:4; } spinlock_t; -#define SPIN_LOCK_UNLOCKED { _RAW_SPIN_LOCK_UNLOCKED, -1, 0 } +#define SPIN_LOCK_UNLOCKED { _RAW_SPIN_LOCK_UNLOCKED, 0xfffu, 0 } #define DEFINE_SPINLOCK(l) spinlock_t l = SPIN_LOCK_UNLOCKED #define spin_lock_init(l) (*(l) = (spinlock_t)SPIN_LOCK_UNLOCKED)